﻿using System;
using System.ComponentModel.DataAnnotations;
using System.Runtime.Serialization;
using System.Xml.Linq;

namespace XamlaApp.ViewModels
{
    [DataContract]
    public class FrameworkElementViewModel : UIElementViewModel
    {
        private double _width = 100;
        [DataMember]
        public virtual double Width
        {
            get { return _width; }
            set
            {
                _width = Math.Round(value);
                if (_width < 0) _width = 0;
                PropertyChanging("Width");
            }
        }

        private double _height = 100;
        [DataMember]
        public virtual double Height
        {
            get { return _height; }
            set
            {
                _height = Math.Round(value);
                if (_height < 0) _height = 0;
                PropertyChanging("Height");
            }
        }

        internal override System.Xml.Linq.XElement GenerateXaml(System.Xml.Linq.XElement element)
        {
            element.Add(new XAttribute("Width", Width), new XAttribute("Height", Height));
            return base.GenerateXaml(element);
        }
    }
}
